require.config({
	baseUrl: "./javascripts/library",
	path: {
		axios: "axios",
		jquery: "jquery",
	},
	shim: {},
});

require(["jquery", "axios"], function ($, axios) {
	let username = $("#login-name");
	let pwd = $("#login-pwd");
	let login_btn = $("#login-btn");

	login_btn.on("click", function (ev) {
		ev.preventDefault();
		axios
			.get("/users/login", {
				params: { username: username.val(), password: pwd.val() },
			})
			.then((response) => {
				console.log(response);
				let data = response.data;
				if (data.success) {
					localStorage.setItem("authorization", data.token);
				}
			})
			.catch((err) => {
				console.log(err);
			});
	});
});
